/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nhadat.action.form;

import javax.servlet.http.HttpServletRequest;
import nhadat.dao.NguoiDungDAO;
import nhadat.entity.TblNguoiDung;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Xe Bay
 */
public class LoginActionForm extends org.apache.struts.action.ActionForm {

    private String tendangnhap;
    private String matkhau;
    private TblNguoiDung nguoiDung;

    public String getTendangnhap() {
        return tendangnhap;
    }

    public void setTendangnhap(String tendangnhap) {
        this.tendangnhap = tendangnhap;
    }

    public String getMatkhau() {
        return matkhau;
    }

    public void setMatkhau(String matkhau) {
        this.matkhau = matkhau;
    }

    public TblNguoiDung getNguoiDung() {
        return nguoiDung;
    }

    public void setNguoiDung(TblNguoiDung nguoiDung) {
        this.nguoiDung = nguoiDung;
    }

    public LoginActionForm() {
        this.nguoiDung = null;
    }

    public LoginActionForm(TblNguoiDung nguoiDung) {
        this.nguoiDung = nguoiDung;
    }

    public LoginActionForm(String tendangnhap, String matkhau) {
        this.nguoiDung = new TblNguoiDung();
        this.tendangnhap = tendangnhap.trim();
        this.matkhau = matkhau.trim();
    }

    /* Ham check username + password valid or not */
    public boolean checkLogin () {
        NguoiDungDAO nguoiDungDAO = new NguoiDungDAO();
        nguoiDung = nguoiDungDAO.authenticate(tendangnhap, matkhau);

        if (nguoiDung != null) {
            return true;
        }
        return false;
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
        nguoiDung = null;
    }

    
}
